package cn.livingCloud.entity.core;

import cn.livingCloud.context.BeanProvider;
import cn.livingCloud.repository.CaseCategoryMapper;
import cn.livingCloud.utils.UuidGenerator;

import java.util.List;

/**
 * 案件分类
 */
public class CaseCategory extends BaseEntity {
    private transient final CaseCategoryMapper categoryMapper = BeanProvider.getBean(CaseCategoryMapper.class);

    private String uuid = UuidGenerator.generate();
    //分类名称
    private String name;
    //分类内容
    private String content;
    //父级分类
    private String parentUuid;

    public CaseCategory() {
    }

    public String getUuid() {
        return uuid;
    }

    public CaseCategory setUuid(String uuid) {
        this.uuid = uuid;
        return this;
    }

    public String getName() {
        return name;
    }

    public CaseCategory setName(String name) {
        this.name = name;
        return this;
    }

    public String getContent() {
        return content;
    }

    public CaseCategory setContent(String content) {
        this.content = content;
        return this;
    }

    public String getParentUuid() {
        return parentUuid;
    }

    public CaseCategory setParentUuid(String parentUuid) {
        this.parentUuid = parentUuid;
        return this;
    }

    public CaseCategory getParent() {
        return categoryMapper.selectByPrimaryKey(this.parentUuid);
    }

    @Override
    public String toString() {
        return "CaseCategory{" +
                "content='" + content + '\'' +
                ", uuid='" + uuid + '\'' +
                ", name='" + name + '\'' +
                ", archive=" + archive +
                ", createDateTime=" + createDateTime +
                '}';
    }

    public void delete() {
        this.setArchive(true);
        categoryMapper.updateByPrimaryKey(this);
        List<CaseCategory> categorys = categoryMapper.findSubCategory(this.uuid);
        for (CaseCategory category : categorys) {
            category.delete();
        }
    }
}